package com.codeavatar.hardwaretester.activity.hardware.bluetooth;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.codeavatar.catools.base.CaBaseActivity;
import com.codeavatar.catools.helper.CaActionBarHelper;
import com.codeavatar.catools.helper.CaLogHelper;
import com.codeavatar.hardwaretester.adapter.CarBlePagerAdapter;
import com.codeavatar.hardwaretester.databinding.ActivityBluetoothCarbleBinding;
import com.codeavatar.hardwaretester.fragment.hardware.CanMessageFragment;
import com.codeavatar.hardwaretester.fragment.hardware.SendCmdFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * +----------------------------------------------------------------------
 * | @Author: codeavatar   @Year：2022
 * +----------------------------------------------------------------------
 * | @Email: codeavatar@aliyun.com
 * +----------------------------------------------------------------------
 **/
public class CarBleActivity extends CaBaseActivity {

    private final String TAG = this.getClass().getSimpleName();

    private ActivityBluetoothCarbleBinding mainBinding;
    private List<String> tabNames = new ArrayList<>();
    private List<Fragment> tabFragments = new ArrayList<>();

    //++++++++++++++++++++++++++++++++++++++
    //++ 内部方法
    //++++++++++++++++++++++++++++++++++++++

    private void doInitLayout(){
        //滚动页
        CarBlePagerAdapter carBlePagerAdapter = new CarBlePagerAdapter(getSupportFragmentManager(),tabFragments,tabNames);
        mainBinding.vprPages.setAdapter(carBlePagerAdapter);
        mainBinding.tabTitles.setupWithViewPager(mainBinding.vprPages);
    }

    //++++++++++++++++++++++++++++++++++++++
    //++ 重写方法
    //++++++++++++++++++++++++++++++++++++++

    @Override
    protected void initBinding() {
        mainBinding = ActivityBluetoothCarbleBinding.inflate(getLayoutInflater());
    }

    @Override
    protected View getLayoutView() {
        return mainBinding.getRoot();
    }

    @Override
    protected void initNavigation() {
        CaActionBarHelper.init().toolbar(getSupportActionBar(),"车载蓝牙");
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {
        tabNames.add("CAN报文");
        tabNames.add("发送指令");
        tabFragments.add(new CanMessageFragment());
        tabFragments.add(new SendCmdFragment());
        this.doInitLayout();
    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        int itemId = item.getItemId();
        if(android.R.id.home == itemId){
            this.finish();
        }else{
            return super.onOptionsItemSelected(item);
        }
        return true;
    }
}
